using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

using QuestFramework;

namespace QuestFramework.UI
{
    public class PlayerInfoWindow : Window
    {
        private WindowTextElement playerHP;
        private WindowTextElement playerMP;
        private WindowTextElement playerName;
        private WindowTextElement playerLevel;
        private WindowTextElement playerXP;
        private WindowTextureElement playerAvatar;
        private int testHPValue;

        public PlayerInfoWindow(Game game) : base(game)
        {
            testHPValue = 1000;
        }

        public override void Initialize()
        {
            windowPosition = new Vector2(10, 10);
            windowFont = parentGame.Content.Load<SpriteFont>("Fonts\\Pericles");
            backgroundTexture = parentGame.Content.Load<Texture2D>("Textures\\playerinfowindow");

            InitializeTextElements();
            InitializeTextureElements();

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            windowTextElements.Remove(playerHP);
            
            testHPValue = 1000 - gameTime.TotalGameTime.Seconds;
            if (testHPValue <= 0)
                testHPValue = 0;
            
            playerHP.Text = testHPValue.ToString() + "/1000";
            windowTextElements.Add(playerHP);

            base.Update(gameTime);
        }

        private void InitializeTextElements()
        {
            playerHP.Text = testHPValue.ToString() + "/1000";
            playerHP.TextPosition = new Vector2((int)windowPosition.X + 70, (int)windowPosition.Y + 140);
            playerHP.TextColor = Color.Black;
            windowTextElements.Add(playerHP);
            
            playerMP.Text = "31/50";
            playerMP.TextPosition = new Vector2((int)windowPosition.X + 70, (int)windowPosition.Y + 180);
            playerMP.TextColor = Color.Black;
            windowTextElements.Add(playerMP);
            
            playerName.Text = "Mike Tyson";
            playerName.TextPosition = new Vector2((int)windowPosition.X + 141, (int)windowPosition.Y + 10);
            playerName.TextColor = Color.Black;
            windowTextElements.Add(playerName);
            
            playerLevel.Text = "1";
            playerLevel.TextPosition = new Vector2((int)windowPosition.X + 235, (int)windowPosition.Y + 60);
            playerLevel.TextColor = Color.Black;
            windowTextElements.Add(playerLevel);
            
            playerXP.Text = "120";
            playerXP.TextPosition = new Vector2((int)windowPosition.X + 195, (int)windowPosition.Y + 97);
            playerXP.TextColor = Color.Black;
            windowTextElements.Add(playerXP);
        }

        private void InitializeTextureElements()
        {
            playerAvatar.Texture = parentGame.Content.Load<Texture2D>("Textures\\mike");
            playerAvatar.TexturePosition = new Vector2((int)windowPosition.X + 15, (int)windowPosition.Y + 15);
            playerAvatar.TextureSize = new Vector2(116, 112);
            playerAvatar.TextureColor = Color.White;
            windowTextureElements.Add(playerAvatar);
        }
    }
}
